<?php
	function tabTit1($nav)
	{
		$tabtit = '';
		$pageurl=$_SERVER["QUERY_STRING"];
		//$nav=array('全部问答','未回复问答');
		// $tabtit .= '<div class="am-tabs am-margin-bottom-lg">';
		$tabtit .= '<ul class="am-tabs-nav am-nav am-nav-tabs">';
		foreach($nav as $k=>$v){
			$cur=($_GET['tab']==$k)?' class="am-active"':'';
			$tabtit.='<li '.$cur.'><a href="'.url_set_value($pageurl,'tab',$k).'">'.$v.'</a>';
		}
		$tabtit .= '</ul>';
		// $tabtit .= '</div>';
		return $tabtit;
	}

	//html_input
	function html_input1($placeholder, $name, $value,$require=1)
	{
		if($require){
			$require = ' form-require ';
			$require1 = ' require ';
		}
		$_output = '';
		$_output .= '<label class="am-u-sm-3 am-u-lg-2 am-form-label '.$require.'">'.$placeholder.' </label>';
		$_output .= '<div class="am-u-sm-9 am-u-end">';
		$_output .= '	<input type="text" class="tpl-form-input" ';
		$_output .= '	 name="'.$name.'" value="'.$value.'" placeholder="请输入'.$placeholder.'" ';
		$_output .= '	 '.$require1.'>';
		$_output .= '</div>';

		return $_output;
	}

	//html_radios
	function html_select1($name, $array, $info, $val_name='',$multiple=false)
	{
		$html = '<select name="'.$name.'" ';
		if($multiple){
			$html .= ' multiple ';
		}
		$html .= "		data-am-selected=\"{searchBox: 1, btnSize: 'sm'}\" >";
		$html .= '	<option value="0">全部'.$val_name.'</option>';
		foreach($array as $key => $val){
			$html .= '		<option value="'.$val['id'].'"';
			if ($info['parent_id'] == $val['id']) {
				$html .= ' selected';
			}
			if ($info['id'] == $val['id']) {
				$html .= ' disabled';
			}
			$html .= ' >';
			$html .= '	'.$val['name_h1'].'</option>';
		}
		$html .= '</select>';
		if($multiple){
			$html .= ' <div class="help-block"> ';
			$html .= ' <small>注：支持多选</small> ';
			$html .= ' </div> ';
		}
		return $html;
	}

	//html_options
	function html_options1($array, $checked, $val_name='')
	{

	    if(is_array($array)){
	        $html = '';
	        foreach($array as $key => $val){
	        	if(!$val_name){
	        		$v['id'] = $key;
	        		$v['name'] = $val;
	        	}else{
	        		$val['name'] = $val[$val_name];
	        	}

	        	$html .= '<option value="'.$val['id'].'"';
	        	if ($val['id'] == $checked) {
	                $html .= ' selected="selected"';
	            }
	            $html .= ' />';
	            // if($val['level']){
	            // 	$html .= str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$val['level']).'└─';
	            // }
	            if($val['adds']){
	            	$html .= $val['adds'];
	            }
	            $html .= $val['name'] . '</option>';
	            if ($val['children']) {
	            	$html .= html_options($val['children'], $checked, $val_name);
	            }
	            unset($children);
	        }
	        $html .= '';
	    }

		return $html;
	}

	//html_radios
	function html_radios1($name, $options, $checked)
	{
		$_output = '';
		foreach($options as $key => $value){
			$_output .= '<label class="am-radio-inline">';
			$_output .= ' <input type="radio" name="'.$name.'" value="'.$key. '" data-am-ucheck';
		    if ((string)$key == $checked) {
		        $_output .= ' checked="checked"';
		    }
			$_output .= ' /> '.$value;
			$_output .= '</label>';
		}

		return $_output;
	}

	//html_checkboxes
	function html_checkboxes1($name,$options,$checked)
	{
	    $_output = '';
		foreach($options as $key => $value){
			$_output .= '<label class="am-checkbox-inline">';
			$_output .= ' <input type="checkbox" name="'.$name.'['.$key.']" value="1" data-am-ucheck';
		    if (is_array($checked)) {
				if($checked[$key]){
		            $_output .= ' checked="checked"';
		        }
		    } elseif ($key == $checked) {
		        $_output .= ' checked="checked"';
		    }
			$_output .= ' /> '.$value;
			$_output .= '</label>';
		}
		return $_output;
	}

	//分页
	function html_showPage1($array,$tag='',$ps='page')
	{
	    // $this->page_num=$pagearr['total_page'];
	    // $pcur_start=$this->pabs($this->page_num,$this->page_cur,$this->single_num);
	    // $this->start=$pcur_start['start'];

		// <div class="am-fr"><{$showPage nofilter}> </div>
        //                 <div class="am-fr pagination-total am-margin-right">
        //                     <div class="am-vertical-align-middle">总记录：<{$total}></div>
        //                 </div>

	    $ps='page';
	    $p=$array['current_page']; //当前页
	    $allNum=$array['total_count']; //总数
	    $allPage=$array['total_page']; //总页数
	    // $tag && $tag='&'.$this->pfit($tag);
	    // '.url_set_value($pageurl,$ps,$pagearr['next_page']).'
	    $pageurl=$_SERVER["QUERY_STRING"];
	    $pStr ='<div class="am-fr"><ul class="pagination">';
	    // $pStr.='<span>共'.$allNum.'条 第'.$p.'/'.$allPage.'页</span>';
		$i=$p-1;

		$side   = 3;
        $window = $side * 2;
		if ($allPage < $window + 6) {

		} elseif ($allPage <= $window) {

		}

	    if($allPage<6||$p<6){
	        for($i=1;$i<=$allPage&&$i<=6;$i++) {
	            $pStr.=($i==$p)?'<li class="disabled"><span>'.$i.'</span></li>':'<li><a href="'.url_set_value1($pageurl,$ps,$i).'">'.$i.'</a></li>';
	        }
	        if($allPage>6){
	            $pStr.=($p<$allPage)?'<li class="disabled"><span>...</span></li><li><a href="'.url_set_value1($pageurl,$ps,$allPage).'">'.$allPage.'</a></li>':'';
	        }
	    }else {
	        $pStr.='<li><a href="'.url_set_value1($pageurl,$ps,1).'">1</a></li><li class="disabled"><span>...</span></li>';
	        for($i=2;$i>0;$i--){
				$pStr.='<li><a href="'.url_set_value1($pageurl,$ps,$p-$i).'">'.(int)($p-$i).'</a></li>';
			}
	        $pStr.='<li><span>'.$p.'</span></li>';
	        $ii=$p;$ii++;
	        for($i=1;$ii<=$allPage;$i++,$ii++) {if($i>2)break;$pStr.='<li><a href="'.url_set_value1($pageurl,$ps,$ii).'">'.$ii.'</a></li>';}
	        if($allPage==$ii) {$pStr.='<li><a href="'.url_set_value1($pageurl,$ps,$allPage).'">'.$allPage.'</a></li>';}
	        else if($allPage-$p>2){$pStr.='<li><span>...</span></li><li><a href="'.url_set_value1($pageurl,$ps,$allPage).'">'.$allPage.'</a></li>';}
	    }
	    $pStr.='</ul></div>';
		$pStr.='<div class="am-fr pagination-total am-margin-right">';
		$pStr.='	<div class="am-vertical-align-middle">总记录：'.$allNum.'</div>';
		$pStr.='</div>';

	    return $pStr;
	}

	//替换url参数
	function url_set_value1($url,$key,$value)
	{
		parse_str($url,$arr);
		$arr[$key]=$value;
		return '?'.http_build_query($arr);
	}